<?php
class Zend_View_Helper_DropList
{
	public function dropList($list, $field, $name = null, $id = null, $class = null, $selected = null, $defaultName = 'Chọn danh mục chính')
	{
		echo "<select name=\"$name\" id=\"$id\" ".(($class)?"class=\"$class\"":"").">\n";
		echo "<option value=\"0\">".$defaultName."</option>";
		$this->createOption($list, $field, 0, null, $selected);
		echo "</select>";
	}
	
	private function createOption($list, $field, $parentId, $space = null, $selected = null)
	{
		foreach ($list as $item) {
			if($item['parent_id'] == $parentId) {
				if($selected == $item[$field[0]]) {
					$more = "selected";
				} else {
					$more = null;
				}
				echo "<option value=\"".$item[$field[0]]."\" $more>".$space.$item[$field[1]]."</option>\n";
				$this->createOption($list, $field, $item[$field[0]], $space.'--', $selected);
			}
		}
	}
}